#include <iostream>
#include <list>
#include<algorithm>
#include <cstring>
#include "ChinesePiece.h"

using namespace std;
using namespace Piece;

void show(const ChineseBoard &board)
{
    for(int y = 0; y < 10; ++y)
    {
        for(int x = 0; x < 9; ++x)
        {
            cout.width(3);
            ChinesePiece *p = board.GetChess(Point(x, y));
            if(p)
            {
                if(p->color == Red)
                {
                    //cout  << "\033[31m\033[0m"<< p->GetName() << endl ;
                    cout << p->GetName();
                }
                else
                {
                    cout << p->GetName();
                }
            }
            else
            {
                cout << "十";
            }
        }
        cout << endl;
    }
}

int main(void)
{
    ChineseGame game;
    show(game.GetBoard());
    while(1)
    {
        int x, y, i, j;
        cout << "轮到：" << (game.GetNextPlayer() == Red?"红方":"黑方") << endl;

        cin >> x >> y >> i >> j;

        if(x == -1)
        {
            break;
        }

        while(!(game.Move(Point(x, y), Point(i, j))))
        {
            cout << "输入出错，请重新输入\n";
            cin >> x >> y >> i >> j;
        }

        show(game.GetBoard());

        if(game.GetWinner() == Black)
        {
            cout << "黑色方胜利\n";
        }
        else if(game.GetWinner() == Red)
        {
            cout << "红色方胜利\n";
        }
        else if(game.GetWinner() == DRAW)
        {
            cout << "平局\n";
        }

    }
    return 0;
}
